<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 600px;
            margin: 100pz auto;
        }
.message{
    display: inline-block;
    font-size: 12px;
    color: #999;
    background: url(./img/mess.png) no-repeat left center;
    padding-left: 20px;
}
.wrong{
    color: red;
    background-image: url(./img/wrong.png);
}

.right{
    color: green;
    background-image: url(./img/right.png);
}
    </style>
</head>
<body>
    <div class="register">
        <input type="password" class="ipt">
        <p class="message">请输入4~8位密码</p>
    </div>
    <script>
// 需求: 表单失去焦点，如果密码不合适，则 p 标签类样式更改，内容也相应变化
//  如何合法，也进行相应变化
let input = document.querySelector('input');
let p = document.querySelector('p');
input.onblur = function () {
    let value = input.value;
    if (value.length >= 4 && value.length <=8) {
        p.className = 'message right';
        p.innerHTML = "密码合法";
    }else{
        p.className = 'message wrong';
        p.innerHTML = "密码不合法";
    }
}
</script>
</body>
</html>